package com.tica.it.itmanage.controller;

import com.tica.catool.common.Result;
import com.tica.it.itmanage.config.jwt.JwtUtil;
import com.tica.it.itmanage.core.dto.UserDetailDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 *
 */
@Api(tags = "用户管理")
@Slf4j
@RestController
@RequestMapping(value = "/staff")
public class StaffController {

    /**
     * 根据token获取用户信息
     *
     * @param req
     * @return
     */
    @ApiOperation(value = "根据ID查询用户")
    @GetMapping("/getStaffInfo")
    //  @RequiresRoles()
    public Result<UserDetailDTO> getUserInfo(HttpServletRequest req) {
        String token = req.getHeader(JwtUtil.HEADER);
        String name = JwtUtil.getUsername(token);
        UserDetailDTO userDetail = new UserDetailDTO();
        userDetail.setName(name);
        return Result.ok().data(userDetail);
    }

}
